package edu.tamu.cse.teamproject1.Database.Interfaces;

import java.util.ArrayList;
import java.util.List;

import edu.tamu.cse.teamproject1.Database.Exceptions.SqlException;

/**
 * Definies the Database API 
 * 
 * This is the entry point for any application wishing to consume and retrieve
 * database information.
 * 
 * @author Christopher Weldon <chris@chrisweldon.net>
 */
public interface DatabaseAPI {
	/**
	 * Retrieves the database name
	 * 
	 * @return The name of the database
	 */
	String getDatabaseName();
	
	/**
	 * Sets the database name
	 * 
	 * @param databaseName
	 */
	void setDatabaseName(String databaseName);
	
    /**
     * Creates a database table loosely based on SQL Query
     * 
     * instead of a formal query string, the input would pass a separate table name and tuple names.
     * it would work essentially the same way but less parsing would be needed
     * 
     * @param tableName String name of the table
     * @param tupleNames Array of ColumnDefinitions
     * @return void
     * @throws TableException
     */
    void createTable(String tableName, ArrayList<IColumnDefinition> tupleNames);
   
    /**
     * Drops a database table
     *
     * @param tableName Name of database table to delete
     * @returns void
     * @throws SqlException
     */ 
    void dropTable(String tableName) throws SqlException;
    
    /**
     * 
     * Inserts records into the database.
     * 
     * essentially the same version as above but less parsing
     * 
     * @param tableName, tuple
     * @return void
     * @throws SqlException
     */
    void insert(String tableName, ITuple tuple) throws SqlException;

    /**
     * Retrieves data from database
     * 
     * The query string passed in must conform to ANSI SQL standards otherwise
     * an exception will be thrown. The function will only process select 
     * requests, but can join across multiple tables simultaneously. 
     *
     * This is the only query that will return records from the database. 
     * We return at the highest interface form, List, to allow casting into
     * the more appropriate Array type. 
     *
     * @param query SELECT sql query statement
     * @returns DatabaseTable
     * @throws SqlException
     */ 
    IDatabaseTable select(String query) throws SqlException;

    /**
     * Updates data in the database
     *
     * The query string passed in must conform to ANSI SQL standards otherwise
     * an exception will be thrown. The function will only perform update 
     * requests and will operate on only one table at a time. 
     *
     * @param tableName Table to update record
     * @param tuples List of tuples to be updated in table
     * @param whereClause Filter on which values to operate
     * @returns void
     * @throws SqlException
     */ 
    void update(String tableName, ArrayList<ITuple> tuples) throws SqlException;

    /**
     * Deletes records in the database
     *
     * The query string passed in must conform to ANSI SQL standards, otherwise
     * an exception will be thrown. The function will only perform delete
     * requests and will operate on only one table at a time. 
     *
     * @param tableName Table to delete records from
     * @param whereClause Filter to limit records to delete
     * @returns void
     * @throws SqlException
     */ 
    void delete(String tableName, String whereClause) throws SqlException;
    
    /**
     * Adds a list of tables to the Database
     * @param tables
     */
    void addListOfTables(List<IDatabaseTable> tableList);
    
    /**
     * Adds a single table to the database
     * @param table
     */
    void addATable(IDatabaseTable table);
    
    /**
     * 
     * @return the list of tables in this database
     */
    List<IDatabaseTable> getTableList();
    
}
